<extend name="Common:grid"/>
<!-- 
 ------------------------------------------------------
  版块管理页面
 ------------------------------------------------------
 -->
<block name="extOptions">
//禁止弹出层自动关闭
$.jqm.params.closeoverlay = false;
$.extend(defaultJqGridOptions,{
	treeGrid: true,
    treeGridModel:"adjacency",
    ExpandColumn:"name",
    ExpandColClick: true,
	colModel:[
		{name:"name",index:"name",width:200,align:"left",sortable:false,editable:true,editrules:{required:true},formoptions:{elmsuffix:"&nbsp;*"}},
		{name:"id",index:"id",width:70,align:"center",editable:false,editrules:{required:true,integer:true}},
		{name:"description",index:"description",width:150,align:"left",sortable:false,editable:true,edittype:"textarea"},
		{name:"module_level",index:"module_level",width:70,align:"center",sortable: false,editable:true,editrules:{required:true},
			formoptions:{elmsuffix:"&nbsp;*"},editoptions:{defaultValue:1},search:false},
	    {name:"module_pid",index:"module_pid",width:70,align:"center",sortable: false,editable:true,editrules:{required:true,integer:true},
	    	formoptions:{elmsuffix:"&nbsp;*"},editoptions:{defaultValue:'0'},search:false},
	    {name:"module_leaf",index:"module_leaf",width:70,align:"center",sortable: false,editable:true,edittype:"select",
	    	formatter:"select",editoptions:{value:"1:是;0:否"},search:false},
	   	{name:"more",width:80,align:"center",sortable:false,editable:false,formatter:actionLinksFormatterMore,
			  formatoptions:{
			  	items:[{
					title:"添加子版块",
					onclick:'openModuleAdd(this);',
					className:'ui-icon-plus'
				}
				]
			},
			search:false
		},
		{name:"seen",index:"seen",width:60,align:"center",sortable:false,editable:true,edittype:"select",
		    formatter:"select",editoptions:{value:"1:可见;0:隐藏"},search:false},
		{name:"url",index:"url",width:120,align:"left",sortable:false,editable:true,editoptions:{
          	dataEvents:[
          		{
	          		type:"dblclick",
	          		fn:editUrl
	          	}
        ]},formoptions:{elmsuffix:"（双击编辑）"},search:false},
        {name:"img",index:"img",width:80,align:"left",sortable:false,editable:true,edittype:"textarea",search:false},
        {name:"contents",index:"contents",width:60,align:"center",sortable:false,editable:true,edittype:"select",
		    formatter:"select",editoptions:{value:"1:是;0:否"},search:false},
		{name:"push_position",index:"push_position",width:80,align:"center",sortable:true,editable:true,editoptions:{defaultValue:"0"},
			editrules:{required:false,integer:true},search:false},
		{name:"position",index:"position",width:80,align:"center",sortable:true,editable:true,editoptions:{defaultValue:"0"},
			editrules:{required:false,integer:true},search:false},
		{name:"push_count",index:"push_count",width:80,align:"center",sortable:false,editable:true,editoptions:{defaultValue:"0"},
			editrules:{required:false,integer:true,minValue:0},search:false},
		{name:"allow_comment",index:"allow_comment",width:80,align:"center",sortable:false,editable:true,edittype:"select",
		    formatter:"select",editoptions:{value:"0:否;1:是"},search:false}
	],
	sortname:"position",
	rownumbers:false,
	rowNum:0
});

$.extend(defaultPagerAddOptions,{width: 400	});
$.extend(defaultPagerEditOptions,{width: 400});

var dialog=gridDialog("module_post_list",{title:"生成页面链接",width:605,modal:false},BASE+"/admin/content/post_list");
//编辑链接地址
function editUrl(e){
	dialog.dialog({
		buttons:{
			"生成":function(){
				var table=$("#load_post_list_table");
				var id=table.getGridParam("selrow");
				var form=$(e.srcElement).parents("form:first");
				if(!isDefined(id)){
					$("#url",form).val("");
				}else{
					$("#url",form).val(id);
				}
				dialog.dialog("close");
			},
			"关闭":function(){
				dialog.dialog("close");
			}
		}
	}).dialog("open");
	$(e).focus();
}
</block>
<block name="extFunction">
function openModuleAdd(link){
	var table=$("#{$layout}_{$Think.ACTION_NAME}_table");
	var id=$(link).attr("rowId");
	var data=$("#{$layout}_{$Think.ACTION_NAME}_table").jqGrid("getRowData",id);
	table.jqGrid("setSelection",id);
	if(data.module_leaf==1){
		gridWarning("请将该版块的<b>最终版块</b>设置为<b>否</b>后重试！");
		//阻止弹出编辑框
		return [false];
	}
	table.editGridRow("new",{
		beforeShowForm:function(form){
			//修改默认参数
			$("#module_level",form).val(parseInt(data.module_level)+1);
			$("#module_pid",form).val(id);
		},
		width : 400
	});
}
//设置只有非子节点才能添加子节点
function actionLinksFormatterMore(cellvalue, options, rowObject){
	if(1==cellvalue) return "";
	return actionLinksFormatter(cellvalue, options, rowObject);
}
</block>